/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.custservice.web;

import java.util.List;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.custservice.service.IEventManageService;
import com.ce.pms.custservice.service.ITrackRecordService;
import com.ce.pms.custservice.vo.CustServiceEventVO;
import com.ce.pms.custservice.vo.TrackRecordVO;
import com.ce.pms.system.custservice.service.IReturnVisitWayService;
import com.ce.pms.system.custservice.vo.ReturnVisitWayVO;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2008-12-24<br>
 */
public class TrackRecordAction extends PmsBaseAction {

	private ITrackRecordService trackRecordService = null;

	private IEventManageService eventManageService; //客户事件Service

	/**
	 * 跟踪方式
	 */
	private IReturnVisitWayService returnVisitWayService = null;
	/**
	 * 功能描述: 初始化事件跟踪主页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-24  <br>
	 */
	public String initMain(@Read TrackRecordVO trackRecordVO,
						   @Read(key = "ec_crd",defaultValue="10")int pageSize,
						   @Read(key = "ec_p", defaultValue="1")	int pageNo){
		trackRecordVO.setPageNo(pageNo);
		trackRecordVO.setPageSize(pageSize);
		Page page = trackRecordService.queryTrackRecordByPage(trackRecordVO.getCustomerServiceEventID(),trackRecordVO);

		setAttribute("trackRecords", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));

		setAttribute("eventID", trackRecordVO.getCustomerServiceEventID());
		return "main";
	}
	/**
	 * 功能描述:初始化事件跟踪添加页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-24  <br>
	 */
	public String initAdd(@Read(key="eventId")Long eventId){
		CustServiceEventVO vo = eventManageService.getCustServEventByID(eventId);
		setAttribute("custServiceEventVO", vo);

		initReturnVisitWay();//缓存跟踪方式
		return "add";
	}

	/**
	 * 功能描述:初始化作废页面<br>
	 * @param eventId
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-24  <br>
	 */
	public String initAside(@Read(key="eventId") @Out(key="eventId") Long eventId,
							@Read(key="trackRecordID") @Out(key="trackRecordID") Long trackRecordID){
		return "aside";
	}
	/**
	 * 功能描述: 导航到列表页面  该列表页面主要用于查看用的,事件详细信息里面查看用<br>
	 * @param trackRecordVO
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-29  <br>
	 */
	public String initList(@Read TrackRecordVO trackRecordVO,
			   						  @Read(key = "ec_crd",defaultValue="10")int pageSize,
			   						  @Read(key = "ec_p", defaultValue="1")	int pageNo){
		trackRecordVO.setPageNo(pageNo);
		trackRecordVO.setPageSize(pageSize);
		Page page = trackRecordService.queryTrackRecordByPage(trackRecordVO.getCustomerServiceEventID(),trackRecordVO);

		setAttribute("trackRecords", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));

		setAttribute("eventID", trackRecordVO.getCustomerServiceEventID());

		return "list";
	}
	/**
	 * 功能描述:初始化事件跟踪详细页面<br>
	 * @param keyword
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2009-1-6  <br>
	 */
	public String initDetail(@Read(key="keyword")Long keyword){
		TrackRecordVO  trackRecord = trackRecordService.getTrackRecordVOByID(keyword);
		ReturnVisitWayVO returnVisitWay = returnVisitWayService.findReturnVisitWayVOById(trackRecord.getReturnVisitWayID());
		setAttribute("trackRecord", trackRecord);
		setAttribute("returnVisitWay", returnVisitWay);
		return "detail";
	}

	/**
	 * 功能描述:添加任务跟踪<br>
	 * @param csEventID
	 * @param trackRecordVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-24  <br>
	 */
	public String addQuestionair(@Read TrackRecordVO trackRecordVO){
		trackRecordVO.setCreator(super.getUserId());
		trackRecordService.addQuestionair(trackRecordVO.getCustomerServiceEventID(), trackRecordVO);
		return "result";
	}
	public String setAside(@Read TrackRecordVO trackRecordVO){
		trackRecordService.setAside(trackRecordVO.getCustomerServiceEventID(), trackRecordVO);
		return "result";
	}
	/**
	 * 功能描述:验证事件跟踪是否可以作废<br>
	 * @param csEventID
	 * @param keyword
	 * Create author:yixianjian <br>
	 * Create on:2008-12-24  <br>
	 */
	public void validateAside(@Read(key="eventID")Long csEventID,
							  @Read(key="keyword")Long keyword){
		trackRecordService.checkSetAsideIsTtue(csEventID, keyword);
	}
	/**
	 * 功能描述:检查事件是否可添加事件跟踪<br>
	 * @param eventId
	 * Create author:yixianjian <br>
	 * Create on:2008-12-26  <br>
	 */
	public void checkAddQuestionairIsTtue(@Read(key="eventId")Long eventId){
		trackRecordService.checkAddQuestionairIsTtue(eventId); //验证该事件是否允许添加跟踪事件
	}
	/**
	 * 功能描述:缓存跟踪方式<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-19  <br>
	 */
	private void initReturnVisitWay(){
		List<ReturnVisitWayVO> returnVisitWayList = returnVisitWayService.getReturnVisitWayList();
		setAttribute("returnVisitWayList", returnVisitWayList);
	}
	public void setTrackRecordService(ITrackRecordService trackRecordService) {
		this.trackRecordService = trackRecordService;
	}
	public void setEventManageService(IEventManageService eventManageService) {
		this.eventManageService = eventManageService;
	}
	public void setReturnVisitWayService(
			IReturnVisitWayService returnVisitWayService) {
		this.returnVisitWayService = returnVisitWayService;
	}
}
